package cn.gdcp.volley_use_seconde;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class MyAdapter extends BaseAdapter {
    private ArrayList<Weather> weatherArrayList;
    private Context context;

    public MyAdapter(Context context,ArrayList<Weather> weatherArrayList){
        this.context=context;
        this.weatherArrayList=weatherArrayList;
    }
    @Override
    public int getCount() {
        return weatherArrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return weatherArrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LayoutInflater layoutInflater= LayoutInflater.from((context));
        view = layoutInflater.inflate(R.layout.list_item,viewGroup,false);

        TextView day=view.findViewById(R.id.txt_day);
        day.setText(weatherArrayList.get(i).getDay());

        ImageView imgResult=view.findViewById(R.id.img_result);
        imgResult.setImageResource(weatherArrayList.get(i).getImgid());

        return view;
    }
}
